package com.deanlib.cabinet.ui.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.deanlib.cabinet.R;

import java.util.List;

/**
 * 左侧多图叠加效果 右侧文本
 * Created by Dean on 2021/8/15
 */
public class MultiImageTextView extends FrameLayout {

    private TextView textView;

    private final ImageView[] imageArr = new ImageView[3];

    public MultiImageTextView(Context context) {
        super(context);
    }

    public MultiImageTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MultiImageTextView);
        String text = typedArray.getString(R.styleable.MultiImageTextView_text);
        typedArray.recycle();

        View.inflate(context, R.layout.layout_multi_image_text_view, this);
        textView = findViewById(R.id.textView);
        imageArr[0] = findViewById(R.id.imageView1);
        imageArr[1] = findViewById(R.id.imageView2);
        imageArr[2] = findViewById(R.id.imageView3);

        setText(text);
    }

    public MultiImageTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public MultiImageTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    public void setText(CharSequence text){
        textView.setVisibility(VISIBLE);
        textView.setText(text);
    }

    public void setImage(List<String> urlList){
        if (urlList!=null){
            for (int i = 0;i< imageArr.length;i++){
                if (urlList.size()>i) {
                    imageArr[i].setVisibility(VISIBLE);
                    Glide.with(this).load(urlList.get(i)).apply(RequestOptions.circleCropTransform())
                            .into(imageArr[i]);
                }
            }
        }
    }

}
